package com.cn.hnust.controller;

import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

import javax.servlet.http.HttpServletRequest;










import net.sf.jasperreports.engine.JRDataSource;
import net.sf.jasperreports.engine.data.JRBeanCollectionDataSource;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;

import com.cn.hnust.entity.ScholarshipApplyBean;


@Controller
public class UploadController {
	
	@RequestMapping(value ="/uploadFile")
	@ResponseBody
	public String uploadFile(MultipartFile file){
		
		
		return "";
	}
	
	
 

    @RequestMapping(value="/pdf/printScholarshipApply")
	public String printScholarshipApply(HttpServletRequest request,Model model) {
		
			List<ScholarshipApplyBean> list = new ArrayList<ScholarshipApplyBean>();
			String path=request.getSession().getServletContext().getRealPath("/");
			String imageAdress=path+"WEB-INF/jasper/ht_logo1.png";
			//String imageAdress="D:\\workspace2\\HTMS20160809\\WebContent\\WEB-INF\\jasper\\ht_logo1.png";
			ScholarshipApplyBean bean = new ScholarshipApplyBean();
			bean.setApplierName("张三爸");
			bean.setApplyFormOwner("张三");
			bean.setArtConsulter("申美丽");
			bean.setCourseName("国文书法课5");
			bean.setCurators("吴馆长");
			bean.setEmail("zhangsan@google.com.cn");
			bean.setFillFormDate("2016-10-25");
			bean.setFormDate("2016-10-25");
			bean.setFormSeqNo("14066241");
			bean.setGuardianName("张三爸");
			bean.setPhoneNo("17059595959");
			bean.setStudentName("张三");
			bean.setApplyAmtLevel(2);
			bean.setHt_logo(imageAdress);
			list.add(bean);
	    // 报表数据源  
	    JRDataSource jrDataSource = new JRBeanCollectionDataSource(list);  
	    // 动态指定报表模板url  
	    model.addAttribute("url", "/WEB-INF/jasper/ScholarshipApply.jasper");  
	    model.addAttribute("format", "pdf"); // 报表格式  
	    model.addAttribute("jrMainDataSource", jrDataSource);  
	          
	    return "iReportView"; // 对应jasper-defs.xml中的bean id  
	} 

    public static void main(String argv[]) {  
        try {  
        FileInputStream fis = null;  
        FileOutputStream fos = null;  
        BufferedInputStream bis = null;  
        BufferedOutputStream bos = null;  
        fis = new FileInputStream("D:/me.png");  
        fos = new FileOutputStream("D:/me-bak.png");  
        if (fis != null && fos != null) {  
            bis = new BufferedInputStream(fis);  
            bos = new BufferedOutputStream(fos);  
        }  
          
        int tmp = -1;  
        while((tmp = bis.read()) != -1) {  
            bos.write(tmp);  
        }  
        bos.flush();  
          
        fis.close();  
        fos.close();  
          
        } catch (IOException e) {  
            e.printStackTrace();  
        }  
    }  
}
